package com.yinhai.activity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import com.why.photoaibum.adapter.PhotoAdappter;
import com.why.photoaibum.entities.PhotoAibum;
import com.why.photoaibum.entities.PhotoItem;

public class PhotoActivity extends Fragment {
	private GridView gv;
	private PhotoAibum aibum;
	private PhotoAdappter adapter;
	private TextView tv;
	private int chooseNum = 0;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.activity_photoalbum_gridview, null);
		tv = (TextView)view.findViewById(R.id.photo_album_chooseNum);
		//aibum = (PhotoAibum)getIntent().getExtras().get("aibum");
		/**获取已经选择的图片**/
		for (int i = 0; i < aibum.getBitList().size(); i++) {
			if(aibum.getBitList().get(i).isSelect()){
				chooseNum++;
			}
		}
		gv =(GridView)view.findViewById(R.id.photo_gridview);
		adapter = new PhotoAdappter(getActivity(),aibum);
		gv.setAdapter(adapter);
		gv.setOnItemClickListener(gvItemClickListener);
		tv.setText(chooseNum+"");
		return view;
	}
	
	
	private OnItemClickListener gvItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			if( aibum.getBitList().get(position).isSelect()){
				aibum.getBitList().get(position).setSelect(false);
				chooseNum--;
			}else{
				aibum.getBitList().get(position).setSelect(true);
				chooseNum++;
			}
			tv.setText(chooseNum+"");
			adapter.notifyDataSetChanged();
		}
	};
	
	
}
